package com.zhs.smartmall.ware.service.impl;


import com.zhs.smartmall.ware.model.WmsPurchaseDetail;
import com.zhs.smartmall.ware.dao.WmsPurchaseDetailDao;
import com.zhs.smartmall.ware.service.IWmsPurchaseDetailService;
import com.zhs.smartmall.ware.dto.WmsPurchaseDetailDto;


import com.zhs.smartmallcommon.exception.ServiceException;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.smartmallcommon.Enum.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.hutool.core.bean.BeanUtil;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;


/**
 *
 * @author 
 * @since 2023-11-15
 */
@Service
@Slf4j
public class WmsPurchaseDetailServiceImpl extends ServiceImpl< WmsPurchaseDetailDao, WmsPurchaseDetail> implements IWmsPurchaseDetailService {

    @Resource
    private WmsPurchaseDetailDao wmsPurchaseDetailDao;

    @Override
    @Transactional
    public R addOrUpdate(WmsPurchaseDetailDto wmsPurchaseDetailDto) {
        if (BeanUtil.isEmpty(wmsPurchaseDetailDto)) throw new ServiceException("数据不能为空");
        WmsPurchaseDetail wmsPurchaseDetail = new WmsPurchaseDetail();
        BeanUtil.copyProperties(wmsPurchaseDetailDto,wmsPurchaseDetail);
        if (wmsPurchaseDetailDto.getId() == null){
            wmsPurchaseDetailDao.insert(wmsPurchaseDetail);
            return R.ok("数据插入成功");
        }else {
            wmsPurchaseDetailDao.updateById(wmsPurchaseDetail);
            return R.ok("数据更新成功");
        }
    }
}